package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.example.utils.SortedListOf;
import java.util.logging.Logger;

public class ContactData implements Comparable<ContactData>{
	
	private String id;
	private String firstname;
	private String lastname;	
	private String home;
	private String mobile;
	private String work;
	private String email;
	private String email2;
	private String address;
	private String bday;
	private String bmonth;
	private String byear;
	private String address2;
	private String phone2;

	public ContactData() {
	}
	
	public ContactData(String firstname, String lastname, 
			String home, String mobile, String work, String email,
			String email2, String address, String bday, String bmonth, String byear,
			String address2, String phone2) {
		this.lastname = lastname;
		this.firstname = firstname;
		this.home = home;
		this.mobile = mobile;
		this.work = work;
		this.email = email;
		this.email2 = email2;
		this.address = address;
		this.bday = bday;
		this.bmonth = bmonth;
		this.byear = byear;
		this.address2 = address2;
		this.phone2 = phone2;
	}

	@Override
	public String toString() {
		return "ContactData [id = " + id + ", firstname=" + firstname + ", lastname=" + lastname
				+ ", home=" + home + ", mobile=" + mobile + ", work=" + work 
				+ ", email=" + email + ", email2="+ email2 + ", address=" + address 
				+  ", bday=" + bday + ", bmonth=" + bmonth + ", byear="
				+ byear + ", address2=" + address2 + ", phone2=" + phone2 + "]";
	}
	
	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this, false);
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj, false);
	}

	@Override 
	public int compareTo(ContactData other) {
		return new CompareToBuilder()
			//.append(firstname + lastname, other.firstname + other.lastname)			
			.append(lastname, other.lastname)
			.append(firstname, other.firstname)			
			.append(address, other.address)
			.append(home, other.home)
			.append(mobile, other.mobile)
			.append(work, other.work)
			.append(email, other.email)
			.append(email2, other.email2)		
			.append(bday, other.bday)
			.append(bmonth, other.bmonth)
			.append(byear, other.byear)
			.append(address2, other.address2)
			.append(phone2, other.phone2)
			.build();
	}
	
	public static final String[] monthNames = new String[]{
	        "-",
	        "January",
	        "February",
	        "March",
	        "April",
	        "May",
	        "June",
	        "July",
	        "August",
	        "September",
	        "October",
	        "November",
	        "December"
	    };
	
	public ContactData withFirstname(String firstname) {
		this.firstname = firstname;
		return this;
	}

	public ContactData withLastname(String lastname) {
		this.lastname = lastname;
		return this;
	}

	public ContactData withAddress(String address) {
		this.address = address;
		return this;
	}

	public ContactData withHome(String home) {
		this.home = home;
		return this;
	}

	public ContactData withMobile(String mobile) {
		this.mobile = mobile;
		return this;
	}

	public ContactData withWork(String work) {
		this.work = work;
		return this;
	}

	public ContactData withEmail(String email) {
		this.email = email;
		return this;
	}

	public ContactData withEmail2(String email2) {
		this.email2 = email2;
		return this;
	}

	public ContactData withBday(String bday) {
		this.bday = bday;
		return this;
	}

	public ContactData withBmonth(String bmonth) {
		this.bmonth = bmonth;
		return this;
	}

	public ContactData withByear(String byear) {
		this.byear = byear;
		return this;
	}

	public ContactData withAddress2(String address2) {
		this.address2 = address2;
		return this;
	}

	public ContactData withPhone2(String phone2) {
		this.phone2 = phone2;
		return this;
	}
	
	public String getId() {
		return id;
	}

	public String getFirstname() {
		return firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public String getAddress() {
		return address;
	}

	public String getHome() {
		return home;
	}

	public String getMobile() {
		return mobile;
	}

	public String getWork() {
		return work;
	}

	public String getEmail() {
		return email;
	}

	public String getEmail2() {
		return email2;
	}

	public String getBday() {
		return bday;
	}

	public String getBmonth() {
		return bmonth;
	}

	public String getByear() {
		return byear;
	}

	public String getAddress2() {
		return address2;
	}

	public String getPhone2() {
		return phone2;
	}

	public static String[] getMonthnames() {
		return monthNames;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setHome(String home) {
		this.home = home;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public void setWork(String work) {
		this.work = work;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setEmail2(String email2) {
		this.email2 = email2;
	}

	public void setBday(String bday) {
		this.bday = bday;
	}

	public void setBmonth(String bmonth) {
		this.bmonth = bmonth;
	}

	public void setByear(String byear) {
		this.byear = byear;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}
	
	public static void assertDbContactsEqual(
			SortedListOf<ContactData> expected, 
			SortedListOf<ContactData> actual) 
	{
        Logger.getGlobal().info("expected " + expected);
        Logger.getGlobal().info("actual   " + actual);
		assertThat("Contacts lists have different sizes", expected.size(), equalTo(actual.size()));
		for (int i = 0; i < expected.size(); i++) 
		{
			ContactData exp = expected.get(i);
			ContactData act = actual.get(i);
			assertThat("Different Firstname", exp.getFirstname(), equalTo(act.getFirstname()));
			assertThat("Different Lastname", exp.getLastname(), equalTo(act.getLastname()));
			assertThat("Different Home", exp.getHome(), equalTo(act.getHome()));
			assertThat("Different Mobile", exp.getMobile(), equalTo(act.getMobile()));
			assertThat("Different Work", exp.getWork(), equalTo(act.getWork()));
			assertThat("Different Email", exp.getEmail(), equalTo(act.getEmail()));
			assertThat("Different Email2", exp.getEmail2(), equalTo(act.getEmail2()));
			assertThat("Different Address", exp.getAddress(), equalTo(act.getAddress()));
			//assertThat("Different Bday", exp.getBday(), equalTo(act.getBday()));
			assertThat("Different Bmonth", exp.getBmonth(), equalTo(act.getBmonth()));
			assertThat("Different Byear", exp.getByear(), equalTo(act.getByear()));
			assertThat("Different Address2", exp.getAddress2(), equalTo(act.getAddress2()));
			assertThat("Different Phone2", exp.getPhone2(), equalTo(act.getPhone2()));		
		}
	}
	
}